//index.js
//获取应用实例
const app = getApp()
const mineService = require('../../service/mine.js');

Page({
  data: {
    title:"我的钱包",
    detailInfo:{},
    unionId:"",
    list: [],
    queryParams: {
      page: 1,
      num: 10
    },
    isLast: false,
    show:false
  },
  onLoad: function () {
    let userinfo = app.globalData.userinfo;
    this.setData({
      unionId: userinfo.unionId
    })
    this.getDetail();
    this.getContentList();
  },
  onShow: function(){
    this.setData({
        show: true
    });
    if (this.data.show == true) {
        let userinfo = app.globalData.userinfo;
        this.setData({
            unionId: userinfo.unionId
        })
        this.getDetail();
    }
  },
  getDetail(){
    let d = {
      unionId:this.data.unionId
    }
    mineService.getMineAccount(d).then(res => {
      if(res.resCode == 0){
        this.setData({
          detailInfo:res.object
        })
      }
    })
  },
  getContentList() {
    let d = {
      ...this.data.queryParams,
      unionId: this.data.unionId
    }
    mineService.getMineTradeList(d).then(res => {
      if (res.resCode == 0) {
        if (!res.object.length) {
          this.setData({
            isLast: true
          });
          return false;
        }
        this.setData({
          list: [
            ...this.data.list,
            ...res.object
          ]
        });
      }
    })
  },
  onReachBottom() {
    if (this.data.isLast) return false;
    this.setData({
      queryParams: {
        page: ++this.data.queryParams.page,
        num: 10
      }
    })
    this.getContentList();
  }
})
